<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="../../common/import.jsp"%>
<html>
<head>
<title></title>
   <style type="text/css">
      .grid_layout{
			width: 99.5%;
			align: center;
	  }
	  .grid_layout table{
			border-collapse: collapse;
			border: 0px solid #e6e7e9; 
			border-width: 1px 1px 1px 1px; 
			text-align: center;
	  }
	  .grid_layout th{
			border: 0px solid #e6e7e9;
			border-width: 0px;
			padding: 2px 0px;
			width: 30%;
			text-align: right;
			vertical-align: middle;
	   }
	  .grid_layout td{
			border: 0px solid #e6e7e9;
			border-width: 0px;
			padding: 2px 0px;
			text-align: left;
			vertical-align: middle;
	  }
	   
   </style>
   <script src="${ctx}/resources/js/jquery.validate.min.js" type="text/javascript"></script>
   <script type="text/javascript">
	   $(function(){
		   $("#formTable").validate({
			   onsubmit: true, // 是否在提交时验证 
			   //onfocusout: false, // 是否在获取焦点时验证 
			   onkeyup: false,
			   validClass: 'checked',
			   rules: {
					moduleName: {
						required: true,
						maxlength: 25,
						remote:{
							 type: "POST",
							 url: "${ctx}/sys/module/validateModuleName.do",
							 dataType: "json", 
							 data: {
								 id: '${module.id}',
								 name: function() {
									   return $("#moduleName").val();
								   }
							 }
						}
					},
					icon: {
						required: true,
						maxlength: 15
					},
					orderIndex: {
						required: true,
						digits: true,
						max: 999
					},
					remark: {
						maxlength: 50
					}
				},
				messages: {
					moduleName: {
						required: "请输入模块名称且长度不大于25",
						remote: jQuery.format("模块名称已经被使用")
					},
					icon: {
						required: "请输入图标",
						maxlength: "长度不能大于{0}"
					},
					orderIndex: {
						required: "请输入模块排序号",
						digits: "必须是整数",
						max: "数字不能大于{0}"
					},
					remark: {
						maxlength: "长度不能大于{0}"
					}
				},
				success:function(label){
					label.addClass("checked").html("&nbsp;");
				},
				submitHandler: function(form) {
					$.blockUI();
					$.ajax({
		    			  url: "${ctx}/sys/module/save.do",   // 提交的页面
		    		      data: $('#formTable').serialize(), // 从表单中获取数据
		    		      type: "POST",
		    		      success: function(data) {
		    		    	  $.unblockUI();
		    		        	if(data.success==true){
		    		        		reloadData();
		    		        		showSuccessMsg();
		    		        		parent.closeWindow();
		    		        	}else{
		    		        		showFailAlert()
		    		        	}
		    		      },
		    		      error: function(xhr) {
		    		    	  $.unblockUI();
		    		    	  showFailAlert2(xhr);
		    		      }
		    		  })
				}
			});
	   })
	   function reloadData(){
    	   var tab = parent.$('#tabs').tabs('getSelected');
   		   var ifram = tab.find('iframe')[0];
   		   ifram.contentWindow.reloadGrid();
       }
	   function onSubmit(){
		   $("#formTable").submit();
		   //document.forms["formTable"].submit();
	   }
       
   </script>
</head>
<body>
	<div class="easyui-layout" region="center" style="text-align: left;" fit="true">
		<div region="center" border="false" style="padding-top: 10px; text-align: left; background: #fff; border: 1px solid #ccc;">
			<form:form id="formTable" method="post" commandName="module">
			    <form:hidden path="id" />
				<table border="0" class="grid_layout" cellpadding="0" cellspacing="0">
					<tr>
						<th><span style="color: red;">*</span>模块名称：</th>
						<td>
						<form:input path="moduleName" id="moduleName"/>
						<form:errors path="moduleName" cssStyle="font-color:red"/>
						</td>
					</tr>
					<tr>
						<th>父模块：</th>
						<td><form:select path="parentId" style="width: 155px;">
						   <form:option value="" label="--请选择--"/>
						   <form:options items="${parentModule}" itemValue="id" itemLabel="moduleName"/>
						</form:select>
						</td>
					</tr>
					<tr>
						<th>模块请求地址：</th>
						<td><form:input path="url" />
						</td>
					</tr>
					<tr>
						<th><span style="color: red;">*</span>模块图标：</th>
						<td><form:input path="icon" id="icon"/>
						</td>
					</tr>
					<tr>
						<th><span style="color: red;">*</span>排序号：</th>
						<td><form:input path="orderIndex" id="orderIndex"/>
						</td>
					</tr>
					<tr>
						<th>状态：</th>
						<td><form:radiobutton path="status" value="1" label="可用" checked="true"/> 
							<form:radiobutton path="status" value="0" label="禁用" /></td>
					</tr>
					<tr>
						<th>是否子节点：</th>
						<td><form:checkbox path="isLeaf" value="1" /></td>
					</tr>
					<tr>
						<th>备注：</th>
						<td><form:textarea path="remark" rows="5" cols="25" /></textarea></td>
					</tr>
				</table>
			</form:form>
		</div>
		<div region="south" border="false" style="text-align: right; padding: 5px 5px 5px 0;">
			<a class="easyui-linkbutton" iconcls="icon-ok" href="javascript:void(0)" onclick="onSubmit();">提交</a>
			<a class="easyui-linkbutton" iconcls="icon-cancel" href="javascript:void(0)" onclick="parent.closeWindow();">取消</a>
		</div>
	</div>
</body>
</html>
